<template>
   <div class="mypublish">
     <!-- 主要在这里写下拉组件 -->
    <mt-loadmore :top-method="loadTop" ref="loadmore" @top-status-change="handleTopChange">
       <div class="mypublish-content" v-for="(item,index) in dataList" :key="index"  @click="goArtical(item.id)">
            <div class="mypublish-content-left">
                 <p>{{item.time |  day}}号</p>
                 <p>{{item.time | normalTime}}</p>
            </div>
            <div class="mypublish-content-right">
                 <p>{{item.title}}</p>
                 <p>{{item.detail}}</p>
                  <div class="mypublish-content-right-icon clearfix">
                        <a href="javascript:void(0)"><img src="../../../../assets/comment/pinglun@2x.png" alt=""><span class="red">{{item.num | number}}</span></a> 
                        <a href="javascript:void(0)"><img src="../../../../assets/comment/guanzhu@2x.png" alt=""><span>{{item.favor_counts |  number}}</span></a>
                         <a href="javascript:void(0)"><img src="../../../../assets/comment/dianzan@2x.png" alt=""><span>{{item.like_counts |  number}}</span></a>
                        <a href="javascript:void(0)">
                            <img src="../../../../assets/comment/liulanliang@2x.png" alt="">
                            <span>{{item.reads_count |  number}}</span> 
                        </a>   
                   </div>
            </div>
       </div>
         <!-- 注意这里是自定的下拉组件 -->
          <div slot="top" class="mint-loadmore-top">
                  <span v-show="topStatus === 'pull'" :class="{ 'rotate': topStatus === 'drop' }">↓   下拉刷新</span>
                  <div v-show="topStatus === 'loading'" class="lo">
                    <load-more :tip="('正在更新')"></load-more>
                  </div>
                  <span v-show="topStatus === 'drop'">↑   释放立即更新</span>
          </div>
    </mt-loadmore>
      <load-more :tip="('加载中...')" v-if="loadMoreShow"></load-more>
        <!-- 如果一条帖子也没有，那么空的图片则显示 -->
           <div class="showimg" v-if="this. dataList.length==0">
                 <img src="../../../../assets/nothing.png" alt="" >
                   <p>空空如也~</p>
                 <p> <a href="javascript:void(0)" @click=" postAdd">思绪翻滚？写一篇帖子给他们看看？</a></p>
           </div>
           <load-more :show-loading="false" :tip="('没有更多了')" background-color="#f5f5f5" v-if="noMoreShow"></load-more>
        <!-- 注意这里是发帖的按钮 -->
        <div class="discuss-goTop" @click="postAdd">
            <i class="iconfont icon-pinglun"></i>
        </div>
   </div>
</template>
<script>
import { dateFormat, LoadMore, cookie } from 'vux';
import { MessageBox, Toast } from 'mint-ui';
export default {
  components: { LoadMore },
    data(){
        return {
           loadMoreShow: false,
           topStatus: '',
            pageNum: 1,
            edit: false,
            selectNum: 0,
            dataList: [],
            selectNum: 0,
            noMoreShow:false,
             flag: true
        }
    },
    created() {
        var _this = this;
        this.$nextTick(function() {
            window.addEventListener('scroll', onScroll)
        })
        // 判断滚动条位置，加载更多
        function onScroll() {
            var scrollTop = document.body.scrollTop;
            var innerHeight = window.innerHeight;
            var offsetHeight = document.body.offsetHeight;
            if (scrollTop + innerHeight >= offsetHeight) {
                if (_this.flag) {
                    if (_this. dataList.length >= 7) {
                        _this.flag = false;
                        _this.getList()
                    }
                }
            }
        }
    },
    methods:{
        goArtical(id) {  //点击评论跳转到想对应得页面
            var token = cookie.get('token');
            let postData = { visitType: 2, informationId: id, token: token ,channel :window.sessionStorage.getItem('channel')?window.sessionStorage.getItem('channel'):'' };
            this.$http.post('/loansupermarket-app/information/insertInformationVisit', postData ).then(function(response) {
                if (response.body.code == '000') {
                    this.$router.push({ path: '/main/mydiscover/artical', query: { id: id } })
                } else if (response.body.code == '444') {
                    this.$router.push({ path: '/main/mydiscover/artical', query: { id: id } })
                }
            })
      },
       handleTopChange: function (status) {  //注意这个是下拉组件中的方法
        this.topStatus = status;
       },
      loadTop() {  // 下拉刷新数据的操作 
            setTimeout(()=>{
                 this.mypublish();
              this.$refs.loadmore.onTopLoaded();
            },500);
      },
        postAdd() {  //如果没有数据的话，就让他跳转到谢帖子的页面
            var token = cookie.get('token');
            // 调用用户信息接口，获取手机号码
            this.$http.post('/loansupermarket-app/user/queryUser', { token: token }).then(function(response) {
                var resBody = response.body;
                if (resBody.code == '000') {
                    this.$router.push({ path: '/main/mine/mydiscover/sponsorassess' });
                } else {
                    this.$router.push({ path: '/login', query: { history: 1 } });
                }
            })

        },
        // 上拉加载数据
        getList() {
            this.pageNum += 1;
            this.loadMoreShow = true;
            var token = cookie.get('token');
            var _this = this;
            setTimeout(function() {
               _this.$http.post('/loansupermarket-app/personal/postList', { pageSize: 7, pageNum:_this.pageNum, token: token },{ headers: {token:token}})
                    .then((response) => {
                        var resBody = response.body;
                        if (resBody.code == '000') {
                           _this.flag = true;
                            _this.loadMoreShow = false;
                            if (resBody.data.length < 7) {
                                _this.noMoreShow = true;
                                _this.flag = false;
                            } else {
                                _this.flag = true;
                            }
                            _this.dataList = _this.dataList.concat(resBody.data);
                          
                        } else if(resBody.code == '444') {
                            this.$router.push({path:'/login',query:{history:1}});
                        }
                    })
            }, 500)
        },
        mypublish(){
             this.noMoreShow = false; 
           var token = cookie.get('token');
            // 加载第一页数据并实例化
            this.$http.post('/loansupermarket-app/personal/postList', { pageSize: 7, pageNum:1, token: token },{ headers: {token:token}})
                .then((response) => {
                    var resBody = response.body;
                    if (resBody.code == '000') {
                       this.dataList.splice(0,resBody.data.length); //下拉请求新的数据，并且将第一页的数据删掉
                      this.dataList = resBody.data.concat(this.dataList); //表示的是将最新的数据插在最前面
                      //this.dataList=resBody.data;
                      
                        if (this.dataList.length < 7) {
                            this.flag = false;
                            this.noMoreShow =true; 
                        }else {
                                this.flag = true;
                            }
                        if( this.dataList.length==0){
                             this.noMoreShow = false; 
                        }
                    }else if(resBody.code == '444'){
                        this.$router.push({path:'/login',query:{history:1}});
                    }else{
                        MessageBox.alert(resBody.mesg);
                    }

                })
         }
    },
     mounted() {
        this.noMoreShow = false; 
        var token = cookie.get('token');
        // 加载第一页数据并实例化
       /*this.$http.post('/loansupermarket-app/personal/postList', { pageSize: 7, pageNum: this.pageNum, token: token },{ headers: {token:token}})
            .then((response) => {
                var resBody = response.body;
                if (resBody.code == '000') {
                    this.dataList = resBody.data;
                    if (this.dataList.length < 7) {
                        this.flag = false;
                        this.noMoreShow = true; 
                    }
                }else if(resBody.code == '444'){
                    this.$router.push({path:'/login',query:{history:1}});
                }else{
                    MessageBox.alert(resBody.mesg);
                }
            })*/
            this. mypublish();
    },
}
</script>
<style lang="scss" scoped>
@import '../../../../scss/variable/base.scss';
.lo .weui-loadmore{
  margin:0px auto;
  line-height:0;
}
.lo{
  padding:1.2em 0 0 0;
}
 .showimg{
       margin-top:rem(120);
           text-align: center;
           p{
              margin-top: rem(40);
               a{
                 text-decoration: underline;
                 font-size: rem(20);
                 color: #00dada;
               }
           }
    }
.mypublish{
    padding: 0px 0.4rem;
    margin-top: 2.9rem;
    width: 100%;
    box-sizing: border-box;
    &-edit{
        position: fixed;
        right: 0.4rem;
        top: 0.35rem;
        z-index: 999;
        color: #fff;
        font-size: 0.4rem;
    }
    &-content{
        margin-bottom: rem(26);
        box-sizing: border-box;
        display: flex;
        &-left{
            flex:3;
          margin-top: rem(26); 
          margin-right: rem(30);
          p:nth-of-type(1){
              color: #333333;
              font-size: rem(38);
              font-weight: bold;
          } 
          p:nth-of-type(2){
              margin-top: rem(12);
              color: #666666;
              font-size: rem(24);
          } 
        }
        &-right{
             flex: 8;
            text-align: left;
            background:#ebebeb; 
            padding:rem(26);
            border-radius:6px;
             p:nth-of-type(1){
              color: #333333;
              font-size: rem(30);
              font-weight: bold;
             } 
            p:nth-of-type(2){
                margin:rem(18) 0;
                color: #666666;
                font-size: rem(26);
                  // 表示的意思的如果文字超过了一行的话，就省略...
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-line-clamp:2;
                -webkit-box-orient:vertical;
            } 
            &-icon{
             a{    
                   float: right;
                   display:block;
                   margin-right: 10px;
                    img{
                        width:rem(35);
                        height:rem(35);
                        vertical-align: middle;
                         padding-right:2px;
                         padding-bottom: 2px;
                        }
                    span{
                        font-size: rem(24);
                        color: #999999;
                        }     
                }
            }
        }
    }
}
// 这个是复选框的样式
.chk_1 {
    display: none; // vertical-align: -15%;
    width: 0.3rem;
    height: 0.3rem;
  }
.chk_1+label {
    color:#fff !important;
    margin-top: 1.1rem;
    background-color: #FFF;
    border: 1px solid #C1CACA;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05),
    inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
    padding: 0.2rem;
    border-radius: 50%;
    display: inline-block;
    position: relative;
    width: 0.1rem;
    height: 0.1rem; 
    margin-right: 10px;
  }
  .chk_1+label:active {

    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px 1px 3px rgba(0, 0, 0, 0.1);
  }
  .chk_1:checked+label {
    font-size: 0.17rem;
    margin-top: 1.1rem;
    background-color: $primaryColor;
    border: 1px solid $primaryColor;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05), inset 15px 10px -12px rgba(255, 255, 255, 0.1);
    color: #243441;
  }
  .chk_1:checked+label:after {
    content: '\2714'; //勾选符号 
    position: absolute;
    top: 0px;
    left: 0px;
    color: #fff;
    width: 100%;
    text-align: center;
    font-size: 1.4em;
    vertical-align: text-top;
  }
  //这个是顶部删除的样式
.deleteDo {
    display: flex;
    width: 100%;
    position: fixed;
    left: 0;
    height: 1.3rem; // line-height: 1.3rem;
    color: #fff;
    bottom: 0;
    &-left {
      flex: 6;
      background: rgba(0, 0, 0, 0.4);
      border-right: 1px solid #fff;
      text-align: left;
      box-sizing: border-box;
      padding: 0 0.4rem;
      .chk_1+label {
        margin-top: 0.35rem;
        background-color: #FFF;
        border: 1px solid #C1CACA;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
        padding: 0.2rem;
        border-radius: 50%;
        display: inline-block;
        position: relative;
        margin-right: 30px; // display: none;
        // vertical-align: -15%;
        width: 0.1rem;
        height: 0.1rem;
      }
      .chk_1:checked+label {
        margin-top: 0.35rem;
        background-color: $primaryColor;
        border: 1px solid $primaryColor;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05), inset 15px 10px -12px rgba(255, 255, 255, 0.1);
        color: #243441;
      }

      span {
        float: right;
        line-height: 1.3rem;
        font-size: 0.3rem;
      }
    }
    &-right {
      font-size: 0.3rem;
      flex: 3;
      line-height: 1.3rem;
      background: rgba(0, 0, 0, 0.4)
    }
  }
  .discuss-goTop{
    box-shadow: 0px 1px 12px rgba(0, 0, 0, 0.2);
    position: fixed;
    bottom: 2rem;
    width: 1.5rem;
    height: 1.5rem;
    background: #fff;
    text-align: center;
    line-height: 1.5rem;
    border-radius: 50%;
    right: 0.5rem;
    animation: myfirst 1.5s infinite linear;
    i {
      font-size: 0.8rem;
      color: $primaryColor;
    }
    @-webkit-keyframes myfirst {
      0% {
        right: 0.2rem;
      }
      50% {
        right: 0.5rem;
      }
      100% {
        right: 0.2rem;
      }
    }
  }
</style>




